package com.undsf.ogd;

import com.sun.org.apache.xml.internal.security.Init;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Arathi on 2015/10/19.
 */
public class Peopleware {
    //角色四维属性编号
    public static final int PropertyIdProgram = 0; //编程
    public static final int PropertyIdScenario = 1; //脚本
    public static final int PropertyIdGraphics = 2; //图像
    public static final int PropertyIdSound = 3; //音乐

    //职业编号
    public static final int JobIdCoder = 0; //程序员
    public static final int JobIdWriter = 1; //编剧
    public static final int JobIdDesigner = 2; //画师
    public static final int JobIdSndEng = 3; //乐手
    public static final int JobIdDirector = 4; //监督/主管
    public static final int JobIdProducer = 5; //制作人
    public static final int JobIdHardEng = 6; //硬件工程师
    public static final int JobIdHacker = 7; //黑客
    //外聘人员的职业
    public static final int JobIdGamer = 8; //游戏爱好者
    public static final int JobIdPlanner = 9; //策划人
    public static final int JobIdComicFan = 10; //漫画爱好者
    public static final int JobIdComicArtist = 11; //漫画家
    public static final int JobIdIllustrator = 12; //插画家
    public static final int JobIdPainter = 13; //画家
    public static final int JobIdMusicFan = 14; //音乐爱好者
    public static final int JobIdMusicComposer = 15; //作曲家
    public static final int JobIdMusicMusician = 16; //音乐家

    //人员类型编号
    public static final int TypeIdEmployee = 0; //社长或常规职员
    public static final int TypeIdGuest = 2; //来客
    public static final int TypeIdFreePlaner = 3; //自由策划
    public static final int TypeIdFreeDesigner = 4; //自由画师
    public static final int TypeIdFreeSoundEng = 5; //自由音乐家

    public static Map<Integer, String> JobNames = new HashMap<>();

    //模板数据
    protected int id;                     //ID 0
    protected int type;                   //类型 1 取值见常量TypeId*
    protected String name;                //名字 2
    protected String nickname;            //昵称 3（外聘人员无昵称）
    protected int faceId;                 //脸部贴图 4 顔G
    protected int bodyId;                 //身体贴图 5 体G
    protected int rank;                   //招聘级别 6 募集P（外聘人员一律为0，但是不可招聘）
    protected int salary;                 //基准年薪 7 年俸（当该人物为外聘人员时，这个数值是外聘人员ID，从0开始）
    protected int contract;               //合约价 8 契約（外聘人员一律为5000，暂时没有作用）
    protected int efficiency;             //工作效率 9 速度（外聘人员级别，公司规模达到或超过时，才能雇佣）
    protected int powerMax;               //体力最大值 10 耐久（外聘人员一律为0）
    protected List<Integer> propertys;   //各项属性 11-14 P S G M
    protected int superPowerUpLeft;      //能力超级提升次数 15 スーパー（super）能力アップ（up）回数（外聘人员一律为3）
    protected int job;                   //当前职位 16 現在（外聘人员为对应职业 1,2,3）
    protected int talent;                //天赋职位 17 適職（外聘人员一律为0）
    protected List<Integer> skillLevels; //技能级别 18-25 ↓職業レベル（level）↓
    protected String desc;               //简述 26（外聘人员的简介在另一张表中）

    //个体数据
    protected int power;                 //体力
    protected float process;             //当前作业进度
    protected Company employer;          //雇主

    public Peopleware(
            int id,
            int type,
            String name,
            String nickname,
            int faceId,
            int bodyId,
            int rank,
            int salary,
            int contract,
            int efficiency,
            int powerMax,
            List<Integer> propertys,
            int superPowerUpLeft,
            int job,
            int talent,
            List<Integer> skillLevels,
            String desc
    ) {
        this.id                = id;
        this.type              = type;
        this.name              = name;
        this.nickname          = nickname;
        this.faceId            = faceId;
        this.bodyId            = bodyId;
        this.rank              = rank;
        this.salary            = salary;
        this.contract          = contract;
        this.efficiency        = efficiency;
        this.powerMax          = powerMax;
        this.propertys         = propertys;
        this.superPowerUpLeft  = superPowerUpLeft;
        this.job               = job;
        this.talent            = talent;
        this.skillLevels       = skillLevels;
        this.desc              = desc;
        //运行期间数据
        this.power = powerMax;
        this.process = 0;
        this.employer = null;
        //如果当前职业技能等级为0，则设置为1
        if (getSkillLevel(job)<=0)
        {
            setSkillLevel(job, 1);
        }
        InitJobNames();
    }

    public static void InitJobNames(){
        if (JobNames == null){
            JobNames = new HashMap<>();
        }
        if (JobNames.size()<=0){
            JobNames.put(JobIdCoder,    "程序员");
            JobNames.put(JobIdWriter,   "编剧");
            JobNames.put(JobIdDesigner, "画师");
            JobNames.put(JobIdSndEng,   "音乐制作");
            JobNames.put(JobIdDirector, "监督");
            JobNames.put(JobIdProducer, "制作人");
            JobNames.put(JobIdHardEng,  "硬件工程师");
            JobNames.put(JobIdHacker,   "黑客");
            //--------------------------------
            JobNames.put(JobIdGamer,         "游戏爱好者");
            JobNames.put(JobIdPlanner,       "策划人");
            JobNames.put(JobIdComicFan,      "漫画爱好者");
            JobNames.put(JobIdComicArtist,   "漫画家");
            JobNames.put(JobIdIllustrator,   "插画家");
            JobNames.put(JobIdPainter,       "画家");
            JobNames.put(JobIdMusicFan,      "音乐爱好者");
            JobNames.put(JobIdMusicComposer, "作曲家");
            JobNames.put(JobIdMusicMusician, "音乐家");
        }
    }

    int getSkillLevel(int skillId)
    {
        return skillLevels.get(skillId);
    }

    boolean setSkillLevel(int skillId, int level)
    {
        skillLevels.set(skillId, level);
        return true;
    }

    public String getName() {
        return name;
    }

    public Company getEmployer(){
        return employer;
    }

    public void setEmployer(Company company){
        this.employer = company;
    }

    public String toString(){
        String employerName = employer!=null ? employer.getName() : "自由";
        String jobName = JobNames.get(job);
        if (type != 0){
            jobName = JobNames.get(talent);
        }
        if (jobName == null) jobName = "";
        return employerName + " " + jobName + " " + name + " " + desc;
    }
}
